package com.serviceprovider.business.module.sp.transaction.services.impl;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.admin.transaction.valueobjects.AdminTransactionCriteria;
import com.serviceprovider.business.module.common.Page;
import com.serviceprovider.business.module.sp.transaction.model.TransactionCriteria;
import com.serviceprovider.business.module.sp.transaction.model.TransactionDetail;
import com.serviceprovider.business.module.sp.transaction.services.dao.interfaces.ITransactionDao;
import com.serviceprovider.business.module.sp.transaction.services.interfaces.ITransactionService;
import com.serviceprovider.business.module.sp.transaction.valueobjects.TransactionDetailsVO;
import com.serviceprovider.business.module.user.model.impl.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

//~--- JDK imports ------------------------------------------------------------

import java.util.LinkedList;
import java.util.List;

@Repository("transactionService")
public class TransactionServiceImpl implements ITransactionService {
    @Autowired
    private ITransactionDao transactionDao;

    public List<TransactionDetailsVO> findNewTransactionsVO(int providerId) {
        List<TransactionDetailsVO> result = new LinkedList<TransactionDetailsVO>();
        List<TransactionDetail>    list   = transactionDao.findNewTransactions(providerId);

        for (TransactionDetail tr : list) {
            result.add(new TransactionDetailsVO(tr));
        }

        return result;
    }

    @Override
    public List<TransactionDetail> findTransactionsByUserId(int providerId) {
        return transactionDao.findTransactionsByUserId(providerId);
    }

    @Override
    public TransactionDetail getTransactionById(int id) {
        return transactionDao.getTransactionById(id);
    }

    @Override
    public List<TransactionDetail> findTransactionsByBatch(int batchId) {
        return transactionDao.findTransactionsByBatch(batchId);
    }

    @Override
    public List<TransactionDetail> findTransactionsByPayee(int payeeid) {
        return transactionDao.findTransactionsByPayee(payeeid);
    }

    @Override
    public List<User> findPayeeListOnTransaction(TransactionDetail transaction) {
        return transactionDao.findPayeeListOnTransaction(transaction);
    }

    @Override
    public List<TransactionDetail> findByProviderAndBatch(int providerId, int batchId) {
        return transactionDao.findByProviderAndBatch(providerId, batchId);
    }

    @Override
    public TransactionDetail insertTransaction(TransactionDetail t) {
        return transactionDao.insertTransaction(t);
    }

    @Override
    public void deleteTransaction(int transactionId) {
        transactionDao.deleteTransaction(transactionId);
    }

    @Override
    public void updateTransaction(TransactionDetail t) {
        transactionDao.updateTransaction(t);
    }

    @Override
    public void updateTransactionStatus(int transactionId, int transactionStatusId) {
        transactionDao.updateTransactionStatus(transactionId, transactionStatusId);
    }

    @Override
    public void updateTransactionSelfFee(int transactionId, int selfFee) {
        transactionDao.updateTransactionSelfFee(transactionId, selfFee);
    }

    @Override
    public List<TransactionDetail> findNumberOfTransactionsInABatch(int batchId) {
        return transactionDao.findNumberOfTransactionsInABatch(batchId);
    }

    @Override
    public Page<TransactionDetail> find(int pageNumber, int pageSize, String sortColumn, String sortOrder) {
        return transactionDao.find(pageNumber, pageSize, sortColumn, sortOrder);
    }

    @Override
    public List<TransactionDetail> findByCriteria(TransactionCriteria criteria) {
        return transactionDao.findByCriteria(criteria);
    }

    @Override
    public List<TransactionDetail> findNewTransactions(int providerId) {
        return transactionDao.findNewTransactions(providerId);
    }

    @Override
    public List<TransactionDetail> findTransactionsbyStatus(int statusid, int providerId) {
        return transactionDao.findTransactionsbyStatus(statusid, providerId);
    }

    @Override
    public void moveTransactionsToNew(List<Integer> ids) {
        transactionDao.moveTransactionsToNew(ids);
    }

    @Override
    public void updateTransactaionCustomerBalance(int transactionId, int customerBalance) {
        transactionDao.updateTransactaionCustomerBalance(transactionId, customerBalance);
    }

    @Override
    public List<TransactionDetail> findByAdminCriteria(AdminTransactionCriteria criteria) {
        return transactionDao.findByAdminCriteria(criteria);
    }

    @Override
    public void moveTransactionToProvider(int transactionId, int providerId) {
        transactionDao.moveTransactionToProvider(transactionId, providerId);
    }

    @Override
    public void moveTransactionsToNewStatus(List<Integer> ids) {
        transactionDao.moveTransactionsToNewStatus(ids);
    }
}



